using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class ApMap : EntityTypeConfiguration<Ap>
    {
        public ApMap()
        {
            // Primary Key
            this.HasKey(t => t.APID);

            // Properties
            this.Property(t => t.ID)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.REFERENCE)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.INVNO)
                .HasMaxLength(8);

            this.Property(t => t.DESC)
                .HasMaxLength(40);

            this.Property(t => t.CHECK)
                .HasMaxLength(6);

            this.Property(t => t.TYPE)
                .IsRequired()
                .HasMaxLength(2);

            this.Property(t => t.INVSEQ)
                .HasMaxLength(6);

            this.Property(t => t.ENTITY)
                .IsRequired()
                .HasMaxLength(4);

            this.Property(t => t.MPTYPE)
                .HasMaxLength(6);

            this.Property(t => t.PAYTYPE)
                .HasMaxLength(6);

            this.Property(t => t.VOUCH_DESC)
                .HasMaxLength(100);

            this.Property(t => t.BATCH)
                .HasMaxLength(8);

            this.Property(t => t.INPABATCH)
                .HasMaxLength(8);

            this.Property(t => t.REF)
                .HasMaxLength(6);

            this.Property(t => t.PV)
                .HasMaxLength(6);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Ap");
            this.Property(t => t.APID).HasColumnName("APID");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.REFERENCE).HasColumnName("REFERENCE");
            this.Property(t => t.INVNO).HasColumnName("INVNO");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.DESC).HasColumnName("DESC");
            this.Property(t => t.BAL).HasColumnName("BAL");
            this.Property(t => t.BALDOL).HasColumnName("BALDOL");
            this.Property(t => t.BALVEND).HasColumnName("BALVEND");
            this.Property(t => t.AMT).HasColumnName("AMT");
            this.Property(t => t.AMTDOL).HasColumnName("AMTDOL");
            this.Property(t => t.AMTVEND).HasColumnName("AMTVEND");
            this.Property(t => t.PDTODAY).HasColumnName("PDTODAY");
            this.Property(t => t.MPDTODAY).HasColumnName("MPDTODAY");
            this.Property(t => t.DUEDATE).HasColumnName("DUEDATE");
            this.Property(t => t.CHECK).HasColumnName("CHECK");
            this.Property(t => t.CKDATE).HasColumnName("CKDATE");
            this.Property(t => t.DATEPD).HasColumnName("DATEPD");
            this.Property(t => t.TYPE).HasColumnName("TYPE");
            this.Property(t => t.DISCOUNT).HasColumnName("DISCOUNT");
            this.Property(t => t.DISCOUNTD).HasColumnName("DISCOUNTD");
            this.Property(t => t.DISCOUNTV).HasColumnName("DISCOUNTV");
            this.Property(t => t.INVSEQ).HasColumnName("INVSEQ");
            this.Property(t => t.ENTITY).HasColumnName("ENTITY");
            this.Property(t => t.MPTYPE).HasColumnName("MPTYPE");
            this.Property(t => t.PAYTYPE).HasColumnName("PAYTYPE");
            this.Property(t => t.JVNO).HasColumnName("JVNO");
            this.Property(t => t.DOCNUM).HasColumnName("DOCNUM");
            this.Property(t => t.PJVNO).HasColumnName("PJVNO");
            this.Property(t => t.PDOCNUM).HasColumnName("PDOCNUM");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.MPDTODAYA).HasColumnName("MPDTODAYA");
            this.Property(t => t.MPDTODAYD).HasColumnName("MPDTODAYD");
            this.Property(t => t.VOUCH_DESC).HasColumnName("VOUCH_DESC");
            this.Property(t => t.UNAPPLAMT).HasColumnName("UNAPPLAMT");
            this.Property(t => t.UNAPPLAMTA).HasColumnName("UNAPPLAMTA");
            this.Property(t => t.UNAPPLAMTD).HasColumnName("UNAPPLAMTD");
            this.Property(t => t.PAYERTYPE).HasColumnName("PAYERTYPE");
            this.Property(t => t.SEMIPOSTED).HasColumnName("SEMIPOSTED");
            this.Property(t => t.POSTED).HasColumnName("POSTED");
            this.Property(t => t.OLDMPDA).HasColumnName("OLDMPDA");
            this.Property(t => t.OLDMPDD).HasColumnName("OLDMPDD");
            this.Property(t => t.OLDMPD).HasColumnName("OLDMPD");
            this.Property(t => t.MODOLDMPD).HasColumnName("MODOLDMPD");
            this.Property(t => t.BATCH).HasColumnName("BATCH");
            this.Property(t => t.INPABATCH).HasColumnName("INPABATCH");
            this.Property(t => t.REF).HasColumnName("REF");
            this.Property(t => t.PV).HasColumnName("PV");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.ISOPENING).HasColumnName("ISOPENING");

            // Relationships
            this.HasRequired(t => t.Vend)
                .WithMany(t => t.Aps)
                .HasForeignKey(d => d.ID);

        }
    }
}
